from ronglian_sms_sdk import SmsSDK


class CCP(object):
    """发送短信的单例类"""
    accId = '8aaf0708780055cd0178d3092c6a4f08'
    accToken = '2789707cb34649e785abee8539469e59'
    appId = '8aaf0708780055cd0178d3092d304f0e'

    def __new__(cls, *args, **kwargs):
        # 判断是否存在类属性_instance _instance是类CCP的唯一对象，即单例
        if not hasattr(CCP, "_instance"):
            cls._instance = super(CCP, cls).__new__(cls, *args, **kwargs)
            cls._instance.sdk = SmsSDK(cls.accId, cls.accToken, cls.appId)
        return cls._instance

    def send_sms_code(self, mobile, code):
        resp = self._instance.sdk.sendMessage(1, mobile, (code, 5))
        return resp


if __name__ == '__main__':
    cpp = CCP()
    cpp.send_sms_code("15635661302", "033220")
